﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Devsoft.Utilities.Exceptions;

namespace Devsoft.Utilities
{
    [DebuggerStepThrough]
    public static class Assert
    {
        [DebuggerStepThrough]
        public static void Test(bool res, Exception exception)
        {
            if (!res)
            {
                throw exception;
            }
        }

        [DebuggerStepThrough]
        public static void Test(bool res, string msg)
        {
            Test(res, new AssertException(msg));
        }

        [DebuggerStepThrough]
        public static void Test(bool res, string msg,params object[] args)
        {
            Test(res,string.Format(msg,args));
        }

        [DebuggerStepThrough]
        public static void That(bool res, Exception exception)
        {
            if (!res)
            {
                throw exception;
            }
        }

        [DebuggerStepThrough]
        public static void That(bool res, string msg)
        {
            That(res, new Exception(msg));
        }

        [DebuggerStepThrough]
        public static void That(bool res, string msg, params object[] args)
        {
            That(res, string.Format(msg, args));
        }

        public static void That(Func<bool> func, string msg)
        {
            That(func,new AssertException(msg));
        }

        public static void That(Func<bool> func, Exception ex)
        {
            try
            {
                Assert.That(func(),ex);
            }
            catch (Exception)
            {
                throw ex;
            }
        }
    }
}
